package my.design.proxy;

import java.lang.reflect.Proxy;

/**
 * @author zp
 * @version 1.0
 * @description: 使用JDK 实现动态代理
 * @date 2022/10/17 18:42
 */
public class JdkDynamicObjectFactory {
    public static <T> T getProxiedObject(Class clazz){
        JdkProxyInvocationHandler jdkProxyInvocationHandler;
        try {
            jdkProxyInvocationHandler = new JdkProxyInvocationHandler(clazz.newInstance());
            return (T) Proxy.newProxyInstance(JdkDynamicObjectFactory.class.getClassLoader(),clazz.getInterfaces(),jdkProxyInvocationHandler);
        }catch (IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }
        return null;
    }
}
